<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./index.js"></script>
</head>
<body>
    <input type="text" class="year">
    <input type="text" class="month">
   
   
   <script>
        
    //    var str  = "abc123.ABC";

    //     //g表示全局匹配 i表示模式修饰标识符，不区分大小写
    //     var regExp  = /[a-b]/gi;

                
    //     //  console.log(regExp.exec(str));

    //       console.log(str.match(regExp));
    window.onload = function(){
        var year = $('.year');
        year.onkeypress = function(){
            var regExp  = /^\d{4}$/;
            if(year.value.match(regExp)){
                console.log('正确');
            }else{
                console.log('错误')
            }
        }
    }    

    </script>
</body>
</html>